import java.util.Iterator;

import RobotPkg.Engine;
import RobotPkg.IEngineListener;
import RobotPkg.IRobotListener;
import RobotPkg.RobotController;
import RobotPkg.evOnOff;
import RobotPkg.lineSeen;

import com.ibm.rational.rhapsody.oxf.RiJMainThread;
import com.ibm.rational.rhapsody.oxf.RiJOXF;


public class RobotTest implements Runnable {

	private static RobotController robot;

	/**
	 * @param args
	 */
	
	public RobotTest(){
		
	}
	
	public static void main(String[] args) { 
		// TODO Auto-generated method stub
		RiJOXF.Init(null, 0, 0, true, args);
		IRobotListener rL = new IRobotListener() {
			
			@Override
			public void robotOn() {
				System.out.println("listener robot is On");
				new Thread(new Runnable() {
					
					@Override
					public void run() {
						
						System.out.println("Wysylam sygnal");
						robot.getSensors().get(1).gen(new lineSeen());
						
					}
				}).run();
			}
			
			@Override
			public void robotOff() {				
			}
		};
		robot = new RobotController(RiJMainThread.instance());
		robot.addListener(rL);
		robot.startBehavior();
		
		RobotTest r = new  RobotTest();
		
		Thread thread = new Thread(r);
		
		thread.run();
		
		RiJOXF.Start();
		
	}

	@Override
	public void run() {
		System.out.println("I'am running");
		IEngineListener wheel1Listener = new IEngineListener() {
			
			@Override
			public void stop() {
				System.out.println("Wheel - Stop");
				
			}
			
			@Override
			public void go() {
				System.out.println("Wheel - Go");
				
			}
			
			@Override
			public void back() {
				System.out.println("Wheel - Back");
				
			}
		};
		
		for(Iterator<Engine> it = robot.getItsEngine(); it.hasNext();){
			Engine e = it.next();
			e.addListener(wheel1Listener);
			System.out.println(e);
		}
		
		
		System.out.println("I am closing");
		robot.gen(new evOnOff());
		System.out.println("Robot is running");
		
		
		
		//System.exit(0);
		
	}

}
